package servlet;

import pojo.Department;
import service.DepartmentService;
import service.DepartmentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 陈金平
 * @Description
 * @create 2020/11/22 14:23
 */
public class AddOneDepartment extends HttpServlet {
    private DepartmentService departmentService = new DepartmentServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");

        Department department = new Department();
        department.setDname(req.getParameter("dname"));

        if (departmentService.addOneDepartment(department) > 0) {
            req.setAttribute("message", "新增成功");
        }
        else {
            req.setAttribute("message", "新增失败");
        }

        req.getRequestDispatcher("get_message.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
